<!DOCTYPE html>
<html lang="en">
<head>
    <base href="${springMacroRequestContext.contextPath}/"/>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Login Form</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            margin: 0;
            padding: 0;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
        }
        .login-container {
            background-color: white;
            border-radius: 5px;
            padding: 20px;
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
            width: 300px;
        }
        .login-container h2 {
            text-align: center;
            margin-bottom: 20px;
        }
        .form-group {
            margin-bottom: 15px;
        }
        .form-group label {
            display: block;
            font-weight: bold;
            margin-bottom: 5px;
        }
        .form-group input {
            width: 93%;
            padding: 10px;
            border: 1px solid #ccc;
            border-radius: 5px;
        }
        .login-button {
            background-color: #435ca7;
            color: white;
            border: none;
            border-radius: 5px;
            padding: 10px 20px;
            width: 100%;
            cursor: pointer;
        }
        .login-button:hover {
            background-color: #434ca9;
        }
        .register-button {
            background-color: #112d32;
            color: white;
            border: none;
            border-radius: 5px;
            padding: 10px 20px;
            width: 100%;
            cursor: pointer;
            margin-top: 10px;
        }
        .register-button:hover {
            background-color: #324243;
        }
    </style>
</head>
<script type="text/javascript" src="static/layui/layui.js"></script>
<script type="text/javascript" src="static/js/md5.js"></script>
<body>
<div class="login-container">
    <h2>登录</h2>
    <div>
        <div class="form-group">
            <label for="username">账号</label>
            <input type="text" id="usernametext" name="username" placeholder="请输入你的账户">
        </div>
        <div class="form-group">
            <label for="password">密码</label>
            <input type="password" id="passwordtext" name="password" placeholder="请输入你的密码">
        </div>
        <input type="button" value="登录" class="login-button" id="login"/>
        <input type="button" value="我要注册" class="register-button" id="register"/>
    </div>
</div>
</body>
<script>
    layui.use(['jquery'],function () {
        $=layui.jquery;
        $("#login").click(function () {
            var username = $("#usernametext").val();//账号
            var password = $("#passwordtext").val();//密码
            if(username==''||password==''){
                layer.msg('账号密码不能为空',function () {});
                return;
            }
            //定义固定盐
            var salt="f1g2h3j4";
            //将输入的明文密码与固定盐进行混淆
            var temp=salt.charAt(1)+""+salt.charAt(5)+password+salt.charAt(0)+""+salt.charAt(3);
            //针对混淆后的密码进行MD5加密
            var pwd=md5(temp);
            $.post('user/userLogin',{userName:username,password:pwd},function (response) {
                if(response.code==200){
                    layer.msg("登录成功",{icon:6},function () {
                    });
                    var data = response.data;
                    var object = JSON.parse(data);//拿到返回的对象
                    var uname =  object.username;//用户名
                    var token  = object.token;//令牌
                    var userid = object.userid;//userID
                    var role = object.role;//角色
                    localStorage.setItem("username", uname);
                    localStorage.setItem("token", token);
                    localStorage.setItem("userid", userid);
                    localStorage.setItem("role", role);
                    window.parent.location.reload();
                }else{
                    layer.msg(response.msg,function () {});
                }
            },'json')
        })

        $("#register").click(function () {
            window.open("");
        })
    })
</script>
</html>
